<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">
<ui:composition>
    <h:panelGroup rendered="#{userBean.user.role.idRole == 1}">
        <h:outputLabel value="This page is for registered users only"/> <br/>
        <p:commandLink value="Sign up" actionListener="#{navigationBean.action('register.xhtml')}"/>
        <h:outputLabel value=" or "/>
        <p:commandLink value="login" actionListener="#{navigationBean.action('login.xhtml')}"/>
    </h:panelGroup>

    <h:form id="form">
        <p:dataTable value="#{userDocumentsBean.documents}" var="document" paginator="true" rows="7">
            <f:facet name="header">
                My documents
            </f:facet>
            <p:column headerText="Name">
                <h:outputText value="#{document.documentName}" />
            </p:column>
            <p:column headerText="Description">
                <h:outputText value="#{document.description}" rendered="#{not empty document.description}" />
                <h:outputText value="without description" rendered="#{empty document.description}" />
            </p:column>
            <p:column headerText="Size (Kb)" >
                <h:outputText value="#{document.size}" />
            </p:column>
            <p:column headerText="Upload date">
                <h:outputText value="#{document.date}" >
                    <f:convertDateTime pattern="dd.MM.yyyy HH:mm"/>
                </h:outputText>
            </p:column>
            <p:column headerText="Delete date">
                <p:outputLabel value="#{documentsBean.document.deleteDate}"
                               rendered="#{documentsBean.document.deleteDate != null}">
                    <f:convertDateTime pattern="dd.MM.yyyy HH:mm"/>
                </p:outputLabel>
                <p:outputLabel value="no deleted" rendered="#{documentsBean.document.deleteDate == null}"/>
            </p:column>
            <p:column headerText="Details">
                <p:commandLink actionListener="#{navigationBean.action('document.xhtml')}" styleClass="ui-icon ui-icon-search">
                    <p:ajax event="click" listener="#{documentsBean.setDocument(document)}"/>
                </p:commandLink>
            </p:column>
            <p:column headerText="Remove">
                <p:commandLink actionListener="#{userDocumentsBean.deleteDocument(document.idDocument)}" styleClass="ui-icon ui-icon-trash">
                    <p:confirm header="Delete file" message="Are you sure?" icon="ui-icon-alert" />
                </p:commandLink>
                <p:confirmDialog global="true">
                    <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
                    <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
                </p:confirmDialog>
            </p:column>
        </p:dataTable>
    </h:form>

</ui:composition>

</html>
